package com.wsoft.im.controller;

import com.wsoft.im.query.group.AddGroupQuery;
import com.wsoft.im.query.group.UpdateGroupQuery;
import com.wsoft.im.service.IImGroupService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 群组 前端控制器
 * @author Z001
 * @since 2025年01月14日 09:21:07
 */
@RestController
@Tag(name = "群组")
@RequestMapping("/im/group")
public class ImGroupController {

    @Resource
    private IImGroupService groupService;

    @Operation(summary = "新增群组", description = "新增群组")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid AddGroupQuery query) {
        boolean b = groupService.insertGroup(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改群组信息", description = "修改群组信息")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid UpdateGroupQuery query) {
        boolean b = groupService.updateGroup(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "获取群组详情", description = "获取群组详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(groupService.getGroupInfo(id));
    }

}
